//
//  AppDelegate+QJTools.m
//  QJReceiveGuests
//
//  Created by hle1 on 2020/11/9.
//

#import "AppDelegate+QJTools.h"

@implementation AppDelegate (QJTools)
+ (void)load {
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        Class class = [self class];
        SEL originSelector = @selector(application:didFinishLaunchingWithOptions:);
        SEL newSelector = @selector(hleapplication:didFinishLaunchingWithOptions:);
        Method oriMethod = class_getInstanceMethod(class, originSelector);
        Method newMethod = class_getInstanceMethod(class, newSelector);
        if (newMethod) {
            BOOL isAddedMethod = class_addMethod(class, originSelector, method_getImplementation(newMethod), method_getTypeEncoding(newMethod));
            if (isAddedMethod) {
                IMP oriMethodIMP = method_getImplementation(oriMethod) ?: imp_implementationWithBlock(^(id selfObject) {});
                const char *oriMethodTypeEncoding = method_getTypeEncoding(oriMethod) ?: "v@:";
                class_replaceMethod(class, newSelector, oriMethodIMP, oriMethodTypeEncoding);
            } else {
                method_exchangeImplementations(oriMethod, newMethod);
            }
        }
    });
}

- (BOOL)hleapplication:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary<UIApplicationLaunchOptionsKey,id> *)launchOptions
{
    [[DoraemonManager shareInstance] install];
    IQKeyboardManager.sharedManager.enable = YES;

    return [self hleapplication:application didFinishLaunchingWithOptions:launchOptions];
}

@end
